package yuejian_07.yuejian_07.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import yuejian_07.yuejian_07.R;
import yuejian_07.yuejian_07.javabean.Comment;

import static yuejian_07.yuejian_07.base.Constant.PHOTO_URL;

/**
 * Created by dell on 2017/11/3.
 */

public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater1;

    public CommentListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater1 = LayoutInflater.from(mContext);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Comment entity = (Comment) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.u_name.setText(entity.getUser_name());
        viewHolder.c_time.setText(entity.getComment_date());
        // System.out.printf("activity_name");
        viewHolder.c_content.setText(entity.getC_content());
        String user_pic =PHOTO_URL+entity.getUser_pic();

        Picasso.with(mContext).load(user_pic).into(viewHolder.u_pic);
        if(viewHolder.u_pic.getDrawable()==null){
            viewHolder.u_pic.setImageResource(R.drawable.no_pic);
        }



    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder
        View v = mLayoutInflater1.from(parent.getContext()).inflate(R.layout.cardview_comment, parent, false);
        return new ViewHolder(v);

    }

    //自定义的V
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView u_pic;
        TextView u_name,c_time,c_content;

        public ViewHolder(View itemView) {
            super(itemView);
            u_name = (TextView) itemView.findViewById(R.id.user_name);
            u_pic = (ImageView) itemView.findViewById(R.id.user_pic);
            c_time= (TextView) itemView.findViewById(R.id.time);
            c_content= (TextView) itemView.findViewById(R.id.content);
        }
    }

}
